import java.util.Scanner;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2021-11-27
 * Time:9:17
 */
class LogInSystem{
    String name;
    String password;

    public LogInSystem(String name, String password) {
        this.name = name;
        this.password = password;
    }

    public void login (String name,String password)throws NameException,PasswordException{
        if(!name.equals(this.name)){
            throw new NameException("用户名错误！");
        }
        if(!password.equals(this.password)){
            throw new PasswordException("密码错误！");
        }
        System.out.println("登陆成功！");
    }

}

class NameException extends RuntimeException{
    public NameException(String message) {
        super(message);
    }
}

class PasswordException extends RuntimeException{
    public PasswordException(String message) {
        super(message);
    }
}

public class LogIn {
    public static void main(String[] args) {
        LogInSystem logInSystem = new LogInSystem("ZhangSan","123456");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名：>");
        String name = scanner.nextLine();
        System.out.print("请输入密码：>");
        String password = scanner.nextLine();
        try {
            logInSystem.login(name,password);
        }catch (NameException e){
            e.printStackTrace();
        }catch (PasswordException e){
            e.printStackTrace();
        }

    }
}
